<?php
/**
 * Description of Moneyclass
 *
 * @author marius
 */
class Money implements Serializable{

    private $valueNote;
    private $valuePiece;
    private $currency;

    function __construct($valueNote, $valuePiece, $currency) {
        $this->valueNote = $valueNote;
        $this->valuePiece = $valuePiece;
        $this->currency=strtoupper($currency);
    }

    function getValueNote() { return $this->valueNote; }
    function getValuePiece() { return $this->valuePiece; }
    function getTotalValue() { return ($this->valueNote + $this->valuePiece); }
    function getCurrency() {return $this->currency; }
    function toString() {return "(".$this->currency.") ".$this->getTotalValue();}
    
    function sameCurrency($mOther)
    {
       return strcmp($this->getCurrency(),$mOther->getCurrency())==0;
    }

    function equals(Money $x)
    {
        if ($x->getCurrency() === $this->getCurrency()) {
            return $x->getValue()==$this->getValue();
        }
        return false;
    }

    /*****************/
    /* serialization */
    /*****************/

    public function serialize()
    {
        return serialize(
            array (
                'valueNote' => $this->valueNote,
                'valuePiece' => $this->valuePiece,
                'currency' => $this->currency
            )
        );
    }

    public function unserialize($data)
    {
        $data = unserialize($data);

        $this->valueNote = $data['valueNote'];
        $this->valuePiece = $data['valuePiece'];
        $this->currency = $data['currency'];
    }
}
?>
